#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
const char* pathname = "/home/wzf/Linux/进程间通信";
const int proj_id = 0x12341234;
const int size = 4096;
const char* filename = "fifo";
key_t GetKey()
{
    key_t key = ftok(pathname, proj_id);
    if(key < 0)
    {
        perror("key");
        exit(1);
    }
    return key;
}
 

int CreatShmHelper(key_t key, int flag)
{
    int shmid = shmget(key, size, flag);
    if(shmid < 0)
    {
        perror("shmget");
        exit(1);
    }
    return shmid;
}
int CreatShm(key_t key)
{
    return CreatShmHelper(key, IPC_CREAT|IPC_EXCL|0664);
}

int GetShm(key_t key)
{
    return CreatShmHelper(key, IPC_CREAT);
}

void Makefifo()
{
    int n = mkfifo(filename, 0666);
    if(n < 0)
    {
        perror("mkfifo");
        exit(1);
    }
}